home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / mmdf / mmdf-IIb.43 / src / tools / setup.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-28  |  8.1 KB  |  309 lines

  1. #include "util.h"
  2. #include "mmdf.h"
  3. /*
  4.  *     MULTI-CHANNEL MEMO DISTRIBUTION FACILITY  (MMDF)
  5.  *
  6.  *
  7.  *     Copyright (C) 1979,1980,1981  University of Delaware
  8.  *
  9.  *     Department of Electrical Engineering
  10.  *     University of Delaware
  11.  *     Newark, Delaware  19711
  12.  *
  13.  *     Phone:  (302) 738-1163
  14.  *
  15.  *
  16.  *     This program module was developed as part of the University
  17.  *     of Delaware's Multi-Channel Memo Distribution Facility (MMDF).
  18.  *
  19.  *     Acquisition, use, and distribution of this module and its listings
  20.  *     are subject restricted to the terms of a license agreement.
  21.  *     Documents describing systems using this module must cite its source.
  22.  *
  23.  *     The above statements must be retained with all copies of this
  24.  *     program and may not be removed without the consent of the
  25.  *     University of Delaware.
  26.  *
  27.  *
  28.  *     version  -1    David H. Crocker    March   1979
  29.  *     version   0    David H. Crocker    April   1980
  30.  *     version  v7    David H. Crocker    May     1981
  31.  *     version   1    David H. Crocker    October 1981
  32.  *
  33.  */
  34. /*      make directories to be used by mmdf
  35.  *
  36.  *  Jan 82  D. Crocker          convert to !traceit before chmod of lockdir
  37.  */
  38. #include <pwd.h>
  39. #include <sys/stat.h>
  40. #include "ch.h"
  41.  
  42. extern char *mmdflogin;        /* login name for mmdf processes */
  43.  
  44. /* logs, programs, delivered mail */
  45.  
  46. extern char
  47.     *logdfldir,
  48.     *phsdfldir,
  49.     *tbldfldir,
  50.     *cmddfldir,
  51.     *chndfldir,
  52.     *mldfldir;
  53.  
  54. extern char     *lckdfldir,
  55.           *pn_quedir;
  56.  
  57. #ifdef JNTMAIL
  58. int daemonuid,
  59.     daemongid;
  60. #define    DAEMON    "daemon"        /* Can be overridden by CC option */
  61. char daemonname[]  = DAEMON;
  62. #endif /* JNTMAIL */
  63.  
  64. /* the queue */
  65.  
  66. extern int queprot;             /* protection on quedfldir[] parent */
  67.  
  68. extern char
  69.     *quedfldir,
  70.     *tquedir,
  71.     *aquedir,
  72.     *squepref,
  73.     *mquedir;
  74.  
  75. extern    int    ch_numchans;
  76. extern    Chan    **ch_tbsrch;
  77.  
  78. int mmdfuid,
  79.     mmdfgid;
  80. int traceit;
  81.  
  82. /* */
  83.  
  84. main (argc, argv)
  85.     int argc;
  86.     char *argv[];
  87. {
  88.     extern struct passwd *getpwnam ();
  89.     struct passwd *mmdfpwd;
  90.     int realid,
  91.     effecid;
  92.     register int i;
  93.  
  94.     mmdf_init (argv[0]);
  95. #ifdef JNTMAIL
  96.     if ((mmdfpwd = getpwnam (daemonname)) == (struct passwd *) NULL)
  97.     {
  98.     printf ("No daemon entry in paswd file (%s)\n", daemonname);
  99.     exit (NOTOK);
  100.     }
  101.     daemonuid = mmdfpwd -> pw_uid;
  102.     daemongid = mmdfpwd -> pw_gid;
  103. #endif
  104.  
  105.  
  106.     while (argc-- > 1)
  107.     if (argv[argc][0] == '-')
  108.         switch (argv[argc][1])
  109.         {
  110.         case 'd':       /* debug              */
  111.         case 'n':       /* like make's switch */
  112.         case 't':       /* trace              */
  113.             traceit = TRUE;
  114.             break;
  115.  
  116.         default:
  117.             printf ("Unknown switch '%s'\n", argv[argc]);
  118.             (void) fflush (stdout);
  119.             exit (-1);
  120.         }
  121.  
  122.     getwho (&realid, &effecid);
  123.     if (effecid != 0)
  124.     printf ("   [Not running with superuser rights]\n");
  125.  
  126.     if (traceit)
  127.     printf ("\n   [Trace only; no actions will be taken]\n");
  128.     else
  129.     {
  130.     printf ("\n   [Intermediate directories will be created, if]\n");
  131.     printf ("   [necessary.  No changes will be made to]\n");
  132.     printf ("   [directories which already exist.]\n");
  133.     }
  134.     putchar ('\n');
  135.     (void) fflush (stdout);
  136.  
  137. /*  get uid & gid for mmdf login, for setting directory ownerships */
  138.  
  139.     if ((mmdfpwd = getpwnam (mmdflogin)) == (struct passwd *) NULL)
  140.     {
  141.     printf ("***\t Login name '%s' not in password file.\n", mmdflogin);
  142.     (void) fflush (stdout);
  143.     exit (NOTOK);
  144.     }
  145.     mmdfuid = mmdfpwd -> pw_uid;
  146.     mmdfgid = mmdfpwd -> pw_gid;
  147.  
  148.     printf ("Login '%s':  uid (%d), gid (%d)\n",
  149.         mmdflogin, mmdfuid, mmdfgid);
  150.     printf ("***\t Make sure Makefile's $(MMDFLOGIN) specifies this name.\n");
  151. /* */
  152.  
  153. /*  create standard directories */
  154.  
  155.     printf ("\nCommand library directory '%s'\n\t[protected at 0711]\n", cmddfldir);
  156.     if (my_drcreat (cmddfldir, 0711, mmdfuid, mmdfgid) >= 0)
  157.     {
  158.     printf ("***\t Make sure Makefile's $(LIBDIR) specifies this directory.\n");
  159.     (void) fflush (stdout);
  160.     }
  161.     printf ("\nLogging directory '%s'\n\t[protected at 0711]\n", logdfldir);
  162.     if (my_drcreat (logdfldir, 0711, mmdfuid, mmdfgid) >= 0)
  163.     {
  164.     printf ("***\t Check and run 'setlogs'.\n");
  165.     printf ("***\t It should chdir to this directory.\n");
  166.     }
  167.     printf ("\nPhase (timestamping) directory '%s'\n\t[protected at 0711]\n", phsdfldir);
  168.     my_drcreat (phsdfldir, 0711, mmdfuid, mmdfgid);
  169.  
  170. #ifndef V4_2BSD
  171.     printf ("\nLocking directory '%s'\n\t[protected at 0777]\n", lckdfldir);
  172.     my_drcreat (lckdfldir, 0777, mmdfuid, mmdfgid);
  173. #endif /* V4_2BSD */
  174.  
  175. #ifdef JNTMAIL
  176.     printf ("\nNIFTP (JNT Mail) Spool directory '%s'\n\t[protected at 0700]\n",
  177.         pn_quedir);
  178.     my_drcreat (pn_quedir, 0700, daemonuid, daemongid);
  179. #endif
  180.  
  181.     printf ("\nName table & telephone scripts '%s'\n\t[protected at 0711]\n", tbldfldir);
  182.     my_drcreat (tbldfldir, 0711, mmdfuid, mmdfgid);
  183.  
  184.     printf ("\nChannel program directory '%s'\n\t[protected at 0700]\n", chndfldir);
  185.     if (my_drcreat (chndfldir, queprot, mmdfuid, mmdfgid) >= 0)
  186.     {
  187.     printf ("***\t Make sure Makefile's $(CHANDIR) specifies this directory.\n");
  188.     (void) fflush (stdout);
  189.     }
  190.  
  191.     if (mldfldir != (char *)0 && !isnull (mldfldir[0]))
  192.     {                           /* all mail delivered in common dir     */
  193.     printf ("\nRecipient users' mailbox directory '%s'\n\t[protected at 0777]\n", mldfldir);
  194.     my_drcreat (mldfldir, 0777, mmdfuid, mmdfgid);
  195.     }
  196. /* */
  197.  
  198. /*  create and set-up queue directory substructure */
  199.  
  200.     printf ("\nMail queue home directory '%s'\n\t[protected at 0777]\n", quedfldir);
  201.     my_drcreat (quedfldir, 0777, mmdfuid, mmdfgid);
  202.                  /* sub directories all open access      */
  203.  
  204.     printf ("\tChanging into queue home directory\n");
  205.     if (chdir (quedfldir) < 0)
  206.     {
  207.     errprt (quedfldir);
  208.     printf ("*** Cannot further process queue directories\n");
  209.     (void) fflush (stdout);
  210.     exit (-1);
  211.     }
  212.     printf ("\tLocking its parent [protected at %0o]\n", queprot);
  213.     if (!traceit)
  214.     if (chmod ("..", queprot) < 0)
  215.         errprt ("quedfldir parent");
  216.                       /* couldn't lock PARENT          */
  217.  
  218.     printf ("Temporary address directory '%s'\n\t[protected at 0777]\n", tquedir);
  219.     my_drcreat (tquedir, 0777, mmdfuid, mmdfgid);
  220.  
  221.     printf ("Queued-address directory '%s'\n\t[protected at 0777]\n", aquedir);
  222.     my_drcreat (aquedir, 0777, mmdfuid, mmdfgid);
  223.  
  224.     printf ("Message text directory '%s'\n\t[protected at 0777]\n", mquedir);
  225.     my_drcreat (mquedir, 0777, mmdfuid, mmdfgid);
  226.  
  227.     for (i = 0; i < ch_numchans; i++) {
  228.     char tmpname[64];
  229.  
  230.     if (ch_tbsrch[i] != (Chan *)NULL)
  231.     {
  232.         (void) sprintf (tmpname, "%s%s", squepref, ch_tbsrch[i]->ch_queue);
  233.         printf ("Queue directory '%s'\n\t[protected at 0777]\n", tmpname);
  234.         my_drcreat (tmpname, 0777, mmdfuid, mmdfgid);
  235.     }
  236.     }
  237.  
  238.     if (traceit)
  239.     printf ("\n   [Trace only; no actions were taken.]\n");
  240.  
  241.     (void) fflush (stdout);
  242.     exit (OK);
  243. }
  244. /* */
  245.  
  246. errprt (pref)
  247.     char pref[];
  248. {
  249.     (void) fflush (stdout);
  250.     perror (pref);
  251.     (void) fflush (stderr);
  252. }
  253.  
  254. my_drcreat (path, prot, uid, gid)
  255.     char *path;
  256.     int prot,
  257.         uid,
  258.         gid;
  259. {
  260.     extern struct passwd *getpwuid ();
  261.     struct stat statbuf;
  262.     struct passwd *pwdptr;
  263.     register int retval;
  264.  
  265.     if (traceit)
  266.     return (0);
  267.  
  268.     if (stat (path, &statbuf) >= OK)
  269.     {                             /* already exists  */
  270.     printf ("\t['%s' already exists.]\n", path);
  271.     statbuf.st_mode &= 04777;
  272.     if (statbuf.st_uid != uid)
  273.     {
  274.         if ((pwdptr = getpwuid (statbuf.st_uid)) != NULL)
  275.         printf ("***\t uid (%s) is not %s\n",
  276.                 pwdptr -> pw_name, mmdflogin);
  277.         else
  278.         printf ("UNREGISTERED owner uid (%d) is not %s\n",
  279.                 statbuf.st_uid, mmdflogin);
  280.     }
  281.     if (statbuf.st_gid != gid)
  282.         printf ("***\t group id is (%d) and not (%d)\n",
  283.             statbuf.st_gid, gid);
  284.  
  285.         /* Allow liberal group permissions to ease management */
  286.     if ((statbuf.st_mode&04707) != (prot&04707))
  287.         printf ("***\t protections (%o) should be (%o)\n",
  288.             statbuf.st_mode, prot);
  289.     return (OK);
  290.     }
  291.  
  292.     printf ("\tCreate it? ");
  293.     (void) fflush (stdout);
  294.     switch (getchar ())
  295.     {
  296.     case 'Y':
  297.     case 'y':
  298.         while (getchar () != '\n')
  299.         continue;       /* DROP ON THROUGH */
  300.     case '\n':
  301.         if ((retval = creatdir (path, prot, uid, gid)) < 0)
  302.         errprt (path);
  303.         return (retval);
  304.     }
  305.     while (getchar () != '\n');
  306.     return (NOTOK);
  307. }
  308.  
  309.